<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>权限资源_编辑</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="<?php echo STATIC_ADMIN; ?>bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="//cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css">

    <link rel="stylesheet" href="<?php echo STATIC_ADMIN; ?>dist/css/AdminLTE.css">
    <link rel="stylesheet" href="<?php echo STATIC_ADMIN; ?>dist/css/skins/_all-skins.css">

    <link rel="stylesheet" href="<?php echo STATIC_ADMIN; ?>dist/css/yc_style.css">
    <style>
        .checkbox-inline+.checkbox-inline, .radio-inline+.radio-inline {margin-left: 0;}
        .checkbox-inline {width: 50%;}
    </style>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="//cdn.bootcss.com/html5shiv/3.7.3/html5shiv.js"></script>
  <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body class="hold-transition skin-blue">
<!-- Site wrapper -->
<div class="wrapper">

  <!-- main -->
  <div class="content-wrapper" style="margin: 0;">

      <!-- page title -->
    <section class="content-header">
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-gear"></i> 系统管理</a></li>
        <li><a href="#">权限资源</a></li>
        <li class="active">编辑</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="alert alert-dismissible" role="alert" style="display: none;">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>提示：</strong><span id="msg">消息</span>
        </div>

      <!-- Default box -->
      <div class="box box-info">
          <div class="box-header with-border">
              <h3 class="box-title">编辑资源</h3>
          </div>

          <form class="form-horizontal" id="acl_add" name="acl_add" method="post" action="<?php echo site_url('system/Acl/save');?>">
              <input type="hidden" id="acl_id" name="acl_id" value="<?php echo $acl['acl_id'];?>">
              <div class="box-body">
                  <div class="form-group">
                      <label for="menu_name" class="col-sm-1 control-label">名称</label>
                      <div class="col-sm-4">
                          <input class="form-control" id="acl_name" name="acl_name" type="text"
                                 datatype="*"
                                 nullmsg="权限名称不能为空"
                                 errormsg="权限名称不能为空"
                                 placeholder="权限名称"
                                 value="<?php echo $acl['acl_name']?>">
                          <div class="Validform_checktip"></div>
                      </div>
                  </div>

                  <div class="form-group">
                      <label for="menu_parent" class="col-sm-1 control-label">模块分组</label>
                      <div class="col-sm-4">
                          <select class="form-control" id="acl_group" name="acl_group"
                                  datatype="*"
                                  nullmsg="请选择模块分组"
                                  errormsg="请选择模块分组">
                              <option value="">≡ 请选择 ≡</option>
                              <?php
                              foreach ($menu_parent as $val) {
                                  if ($acl['acl_group']==$val['menu_id']) {
                                      echo '<option value="'.$val['menu_id'].'" selected>'.$val['menu_name'].'</option>';
                                  } else {
                                      echo '<option value="'.$val['menu_id'].'">'.$val['menu_name'].'</option>';
                                  }
                              }
                              ?>
                          </select>
                          <div class="Validform_checktip"></div>
                      </div>
                  </div>

                  <div class="form-group">
                      <label for="acl_controller" class="col-sm-1 control-label">控制器</label>
                      <div class="col-sm-4">
                          <select class="form-control" id="acl_controller" name="acl_controller"
                                  datatype="*"
                                  nullmsg="请选择控制器"
                                  errormsg="请选择控制器"
                                  onchange="getActionList($(this).children('option:selected').val());">
                              <option value="">≡ 请选择 ≡</option>
                              <?php
                              foreach ($controller as $key=>$val) {
                                  if ($acl['acl_controller']==$key) {
                                      echo '<option value="'.$key.'" selected>'.$key.'</option>';
                                  } else {
                                      echo '<option value="'.$key.'">'.$key.'</option>';
                                  }
                              }
                              ?>
                          </select>
                          <div class="Validform_checktip"></div>
                      </div>
                  </div>
                  
                  <div class="form-group" id="acl_action_box" style="display: none;">
                      <label class="col-sm-1 control-label">操作方法</label>
                      <div class="col-sm-4">
                          <div class="well well-sm" id="acl_action_list" style="overflow-y:scroll; height:auto;max-height: 200px;"></div>
                      </div>
                  </div>
              </div>

              <div class="box-footer">
                  <a href="<?php echo site_url('system/Acl/index');?>" class="btn btn-default" role="button">取消</a>
                  <button type="submit" class="btn btn-info pull-right">保存</button>
              </div>
          </form>
      </div>
      <!-- /.box -->

    </section>
    <!-- /.content -->
  </div>
  <!-- main end -->
</div>
<!-- ./wrapper -->

</body>
</html>
<!-- jQuery 2.2.3 -->
<script src="<?php echo STATIC_COMMON; ?>plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="<?php echo STATIC_ADMIN; ?>bootstrap/js/bootstrap.min.js"></script>
<!-- layer 3.0.3 -->
<script src="<?php echo STATIC_COMMON; ?>plugins/layer/layer.js"></script>

<!-- Validform 5.3.2 -->
<script src="<?php echo STATIC_COMMON; ?>plugins/Validform/Validform_v5.3.2.js"></script>

<!-- other -->
<script src="<?php echo STATIC_ADMIN; ?>dist/js/yc_app.js"></script>

<script>
    $(function() {
        getActionList($('#acl_controller').children('option:selected').val());

        ycApp.initValidator();
    });
    
    //根据控制器名加载操作方法列表
    function getActionList(selected) {
        var _controller = selected,
            _action = $('#acl_action_box #acl_action_list');
        isDisplayAction_box(selected);
        var _option = '';
        $.getJSON('<?php echo site_url('Common/get_all_action/');?>'+_controller, function ($result) {
            $.each($result['data'], function (i, v) {
                //匹配已选择的操作方法
                if ('<?php echo str_replace('|', ',', $acl['acl_action']); ?>'.match(v)) {
                    _option += '<label class="checkbox-inline"><input type="checkbox" id="action_'+v+'" name="acl_action[]" value="'+v+'" checked> '+v+'</label>';
                } else {
                    _option += '<label class="checkbox-inline"><input type="checkbox" id="action_'+v+'" name="acl_action[]" value="'+v+'"> '+v+'</label>';
                }

            });
            _action.html(_option);
        });
    }

    //通过控制器下拉菜单值判断操作方法名称容器是否显示
    function isDisplayAction_box(obj) {
        if (obj==0) {
            $('#acl_action_box').slideUp();
            return false;
        } else {
            $('#acl_action_box').slideDown();
        }
    }
</script>
